<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>供应商拖车业务管理</title>
    <s:head/>
</head>
<script type="text/javascript">
    var bstate = "${trailState}";
    var formSetting = {
        title: "查询拖车业务信息",
        module: 'query',
        columns: [{
            name: "businessId",
            label: "业务编号"
        }, {
            name: "trailState",
            label: "业务状态",
            type: "dropdown",
            dropdownType: "ajax",
            url: "../base/dropdown-trailState",
            op: "eq",
            minLength: 0
        }, {
            name: "so",
            label: "SO号"
        }, {
            name: "confirmTime",
            label: "业务提交时间从",
            type: "date",
            op: "ge"
        }, {
            name: "confirmTime",
            label: "到",
            type: "date",
            op: "le"
        }, {
            name: "reqNo",
            label: "交接单号"
        }, {
            name: "customer.name",
            label: "客户名称"
        }],
        buttons: {
            custom: [
                {
                    id: "updatebtn-1",
                    value: "业务流转",
                    click: function () {
                        var id = $("#trailsDataGrid").jqGrid("getGridParam",
                                                             "selrow");
                        if (id) {
                            var ret = $("#trailsDataGrid").jqGrid('getRowData', id);
                            var iddata = "id=" + ret.id;
                            $.ajax({
                                       url: "trail-checkValidatePass",
                                       dataType: "json",
                                       data: iddata,
                                       success: function (data) {
                                           if (!data) {
                                               return;
                                           }
                                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                                           if (msg.state == 1) {
                                               jw.confirm("确定要该业务进行业务流转?", function () {
                                                              jw.dialog({
                                                                            iframe: 'bizFlow-supChoiceList?sup_type=F&id='
                                                                                    + id,
                                                                            width: 500,
                                                                            height: 200
                                                                        });
                                                          },
                                                          function () {
                                                              return;
                                                          });
                                           } else if (msg !== undefined && msg != "" && msg.state
                                                                                        == 0) {
                                               jw.alert("只有处于审核状态的业务才可以进行业务流转操作。");
                                           } else {
                                               jw.alert(msg.msg);
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "updatebtn0",
                    value: "查看详细",
                    click: function () {
                        var id = $("#trailsDataGrid").jqGrid("getGridParam",
                                                             "selrow");
                        if (id) {
                            window.location.href =
                                    "trail-findForSupToValidate?id=" + id
                                    + "&identify=checkDetailForSup";
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "updatebtn1",
                    value: "审核",
                    click: function () {
                        var id = $("#trailsDataGrid").jqGrid("getGridParam",
                                                             "selrow");
                        if (id) {
                            var ret = $("#trailsDataGrid").jqGrid('getRowData', id);
                            var iddata = "id=" + ret.id + "&opType=tgsh";
                            $.ajax({
                                       url: "trail-checkValidatePass",
                                       dataType: "json",
                                       data: iddata,
                                       success: function (data) {
                                           if (!data) {
                                               return;
                                           }
                                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                                           if (msg.state == 1) {
                                               jw.confirm("确定要该业务通过审核?", function () {
                                                              $.ajax({
                                                                         url: "trail-validatePass",
                                                                         dataType: "json",
                                                                         data: iddata,
                                                                         success: function (data) {
                                                                             jw.alert(msg.msg);
                                                                             $("#trailsDataGrid").jqGrid(
                                                                                     "setGridParam",
                                                                                     {
                                                                                         search: true
                                                                                         // 将jqGrid的search选项设为true
                                                                                     }).trigger("reloadGrid",
                                                                                                [{
                                                                                                    page: 1
                                                                                                }]);
                                                                             window.location.href =
                                                                                     "trail-findForSupToValidate?id="
                                                                                     + id
                                                                                     + "&identify=checkDetailForSup";//保存成功后跳转到查看详细页面
                                                                         }
                                                                     });
                                                          },
                                                          function () {
                                                              return;
                                                          });
                                           } else if (msg !== undefined && msg != "" && msg.state
                                                                                        == 0) {
                                               jw.alert("只有处于待审核状态的业务才可以进行审核操作。");
                                           }
                                           else {
                                               jw.alert(msg.msg);
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "updatebtn11",
                    value: "驳回业务",
                    click: function () {
                        var id = $("#trailsDataGrid").jqGrid("getGridParam",
                                                             "selrow");
                        if (id) {
                            var ret = $("#trailsDataGrid").jqGrid('getRowData', id);
                            var iddata = "id=" + ret.id + "&opType=bh";
                            $.ajax({
                                       url: "trail-checkValidatePass",
                                       dataType: "json",
                                       data: iddata,
                                       success: function (data) {
                                           if (!data) {
                                               return;
                                           }
                                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                                           if (msg.state == 1) {
// 										jw.confirm("确定要驳回该业务?",function(){
// 											$.ajax({
// 												url : "trail-validateReject",
// 												dataType : "json",
// 												data : iddata,
// 												success : function(data) {
// 													jw.alert($.parseJSON(data.msg).msg);
// 													$("#trailsDataGrid").jqGrid("setGridParam",
// 															{
// 																search : true
// 															// 将jqGrid的search选项设为true
// 															}).trigger("reloadGrid", [ {
// 														page : 1
// 													} ]);
// 												}
// 											});
// 										},
// 										function(){return;});
                                               jw.dialog({
                                                             iframe: '../business/rejectContent-reject?id='
                                                                     + id + "&type=2",
                                                             title: "驳回",
                                                             iframeFetchTitle: false,
                                                             width: 600,
                                                             height: 150
                                                         });
                                           } else if (msg !== undefined && msg != "" && msg.state
                                                                                        == 0) {
                                               jw.alert("只有处于待审核状态的业务才可以进行驳回业务操作。");
                                           }
                                           else {
                                               jw.alert(msg.msg);
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "cancelBtn",
                    value: "取消订单",
                    click: function () {
                        var id = $("#trailsDataGrid").jqGrid("getGridParam",
                                                             "selrow");
                        if (id) {
                            var selectedIds = $("#trailsDataGrid").jqGrid("getGridParam", "selrow");
                            var rowDatas = $("#trailsDataGrid").jqGrid('getRowData', selectedIds);
                            var row = rowDatas["trailState"];
                            if (row == "申请取消订单") {
                                jw.confirm("确定要取消该业务?", function () {
                                               var iddata = "id=" + id;
                                               $.ajax({
                                                          url: "trail-supCancelBill",
                                                          dataType: "json",
                                                          data: iddata,
                                                          success: function (data) {
                                                              jw.alert($.parseJSON(data.msg).msg);
                                                              $("#trailsDataGrid").jqGrid("setGridParam",
                                                                                          {
                                                                                              search: true
                                                                                              // 将jqGrid的search选项设为true
                                                                                          }).trigger(
                                                                      "reloadGrid", [{
                                                                          page: 1
                                                                      }]);
// 											window.location.href="trail-listForSupToValidate";//保存成功后刷新列表
                                                          }
                                                      });
                                           },
                                           function () {
                                               return;
                                           });
                            } else {
                                jw.alert("此状态不能取消订单!")
                            }
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "excelBtn",
                    value: "导出Excel",
                    click: function () {
                        //组装自定义filters
                        var rules = "";// 定义rules
                        $.each($("#" + $.mrdForm.formContainerId
                                 + " td[id^='td_control_']"), function (i, n) {
                            var control = $(n).children().first();
                            if (!$.mrdForm.isEmpty(control.val())) {
                                rules += "{'field':'" + control.attr('name')
                                         + "','op':'cn','data':'"
                                         + control.val() + "'},";// 组装rules
                            }
                        });
                        // 如果没有查询条件，则返回
                        if (!$.mrdForm.isEmpty(rules)) {
                            rules = rules.substring(0, rules.length - 1);
                            var filters = '{"groupOp":"AND","rules":[' + rules + ']}';// 定义filters
                            window.location.href = "trail-exportExcel?filters=" + filters;
                        } else {
                            window.location.href = "trail-exportExcel";
                        }

                    }
                }/* ,
                 {
                 id : "updatebtn2",
                 value : "业务数据上传",
                 click : function() {
                 var id = $("#trailsDataGrid").jqGrid("getGridParam",
                 "selrow");
                 if(id) {
                 jw.confirm("确定要上传当前选择业务?",function(){
                 var ret = $("#trailsDataGrid").jqGrid('getRowData',id);
                 var data = "id=" + ret.id;
                 $.ajax({
                 url : "trail-validateUpload",
                 dataType : "json",
                 data : data,
                 success : function(data) {
                 jw.alert(data.msg);
                 $("#trailsDataGrid").jqGrid("setGridParam",
                 {
                 search : true
                 // 将jqGrid的search选项设为true
                 }).trigger("reloadGrid", [ {
                 page : 1
                 } ]);
                 }
                 });
                 },
                 function(){return;});
                 } else {
                 jw.alert("请点击需要操作的数据!");
                 }
                 }
                 } */
            ]
        },
        grid: {
            id: "trailsDataGrid",
            title: "查询结果",
            url: "trail-findListForSupToValidate",
            //multiselect : true,
            /* postData : {
             "pid" : pid
             }, */
            postData: {
                "trailState": bstate
            },
            colModel: [{
                index: "ID",
                name: "id",
                hidden: true
            }, {
                index: "businessId",
                name: "businessId",
                label: "业务编号"
            }, {
                index: "reqNo",
                name: "reqNo",
                label: "交接单号"
            }, {
                index: "customerNAME",
                name: "customer.name",
                label: "业务委托人"
            }, {
                index: "shipper",
                name: "shipper.company",
                label: "实际托运人"
            }, {
                index: "so",
                name: "so",
                label: "SO号"
            }, {
                index: "confirmTime",
                name: "confirmTime",
                label: "业务提交时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "validateState",
                name: "trailState",
                label: "审核状态"
            }, {
                index: "validator",
                name: "validator.name",
                label: "审核人"
            }, {
                index: "validateTime",
                name: "validateTime",
                label: "审核时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "realSupId",
                name: "realSupId",
                label: "是否来自业务流转"
            } /*, {
             index : "en",
             name : "en",
             label : "英文名"
             }, {
             index : "identifier",
             name : "identifier",
             label : "标识符"
             }, {
             index : "use_state",
             name : "use_state",
             label : "使用状态",
             formatter : function(cellvalue, options, rowObject) {
             if (cellvalue == "0") {
             return "启用";
             } else {
             return "禁用";
             }
             }
             }, {
             index : "updateUser",
             name : "updateUser",
             label : "修改人"
             }, {
             index : "updateDate",
             name : "updateDate",
             label : "修改时间"
             }  */],
            sortname: "businessId",
            sortorder: "desc",
            jsonReader: {
                root: "trails"
            },
            loadComplete: function (data) {
                var ids = $("#trailsDataGrid").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                    var arrayData = $("#trailsDataGrid").getRowData(ids[i]);
                    if (arrayData.realSupId == "") {
                        //$("#trailsDataGrid").setCell(ids[i], "realSupId", "待确认");
                    }
                    else {
                        var rsid = arrayData.realSupId.split(":")[0];
                        var fstate = arrayData.realSupId.split(":")[1];
                        $("#trailsDataGrid").setCell(ids[i], "realSupId", fstate);
                    }
                    if (arrayData.trailState == "驳回状态") {
                        $($("#" + arrayData.id).find("td")[7]).addClass("biz_state_reject");
                    }
                }
            },
            ondblClickRow: function () {
                var selectedRowId = $("#trailsDataGrid").getGridParam("selrow");
                if (selectedRowId) {
                    var selectedRow = $("#trailsDataGrid").getRowData(selectedRowId);
                    if (selectedRow.trailState == "草稿状态") {
                        //selectedRow.busiId
                        location.href =
                                "business-updateSingle?id=" + selectedRow.id + "&singleType=C";
                    } else {
// 						location.href = "business-updateSingle?id="+selectedRow.id+"&singleType=C&identification=list";
                        location.href =
                                "trail-findForSupToValidate?id=" + selectedRow.id
                                + "&identify=checkDetailForSup";
                    }
                }
            }
        }
    };
    $(document).ready(function () {
        $("#trailsDataTable").mrdForm(formSetting);
    });
</script>
<body>
<div id="trailsDataTable"></div>
</body>
</html>
